package com.yuanzong.wuliu.service.system.notice.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuanzong.wuliu.common.vo.ApiResultPage;
import com.yuanzong.wuliu.mapper.system.notice.SystemNoticeMapper;
import com.yuanzong.wuliu.model.system.notice.SystemNotice;
import com.yuanzong.wuliu.model.system.notice.query.*;
import com.yuanzong.wuliu.service.system.notice.ISystemNoticeService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

@Service("systemNoticeService")
public class SystemNoticeServiceImpl extends ServiceImpl<SystemNoticeMapper, SystemNotice> implements ISystemNoticeService {

    // 逻辑删除
    protected static final boolean logicalDeleted = false;

    @Autowired
    private SystemNoticeMapper systemNoticeMapper;

    //========================================================================================//
    // Service服务接口操作
    //========================================================================================//

    @Override
    public List<SystemNotice> querySubject(SystemNoticeListQuery query) throws Exception {
        List<SystemNotice> systemNoticeList = null;
        QueryWrapper<SystemNotice> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("create_time");
        systemNoticeList = super.getBaseMapper().selectList(queryWrapper);
        return systemNoticeList;
    }

    @Override
    public ApiResultPage<SystemNotice> pageSubject(SystemNoticePageQuery query) throws Exception {
        ApiResultPage<SystemNotice> systemNoticePageList = null;
        Page<SystemNotice> systemNoticePage = new Page<>(query.getPageNum(), query.getPageSize());
        QueryWrapper<SystemNotice> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("create_time");
        systemNoticePage = super.baseMapper.selectPage(systemNoticePage, queryWrapper);
        systemNoticePageList = ApiResultPage.create(query.getPageNum(), query.getPageSize(), systemNoticePage);
        return systemNoticePageList;
    }

    //========================================================================================//
    // HTTP服务接口操作
    //========================================================================================//

    //========================================================================================//
    // extend methods
    //========================================================================================//


    //========================================================================================//
    // The end
    //========================================================================================//

}
